package com.flyme.module.order.client.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@Getter
public enum OrderTypeEnum implements IEnum {
    vip("OT_VIP", "vip购买"), top_up("OT_TOP", "充值"), course("OT_COURSE", "课程"), live("OT_LIVE", "直播报名"), appraisal("OT_APPRAISAL", "能力测评"),
    offcourse("OT_OFFCOURSE", "线下课程"),examnation("OT-EXAM","考试报名"),studycourse("OT_STUDY","继续教育");
    public String text;
    @EnumValue
    public String code;

    OrderTypeEnum(String code, String text) {
        this.text = text;
        this.code = code;
    }

    OrderTypeEnum(String code) {
        this.text = getText(code);
        this.code = code;
    }


    public static String getText(Object code) {
        String v = "";
        for (OrderTypeEnum accountTypeEnum : values()) {
            if (accountTypeEnum.code.equals(code)) {
                v = accountTypeEnum.text;
                break;
            }
        }
        return v;


    }

    public static String getName(String code) {
        String v = "";
        for (OrderTypeEnum accountTypeEnum : values()) {
            if (accountTypeEnum.code.equals(code)) {
                v = accountTypeEnum.name();
                break;
            }
        }
        return v;
    }

    public static OrderTypeEnum getEnum(String code) {
        for (OrderTypeEnum accountTypeEnum : values()) {
            if (accountTypeEnum.code.equals(code)) {
                return accountTypeEnum;
            }
        }
        return null;
    }

    public static Map<String, Object> getMap() {
        Map<String, Object> map = new HashMap<>();
        for (OrderTypeEnum educationEnum : values()) {
            map.put(educationEnum.code, educationEnum.text);
        }
        return map;
    }

    public static void main(String[] args) {
        System.out.print(getName("OT_VIP"));
    }

    @Override
    public Serializable getValue() {
        return this.code;
    }

}
